//
//  LHStatusTableViewCell.swift
//  sina_weibo
//
//  Created by 刘刘海强 on 16/5/13.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

import UIKit
import SnapKit

let StatusTableViewCellMargin: CGFloat = 10

class LHStatusTableViewCell: UITableViewCell {
    
    var toolBarTop: Constraint?
    var statusViewModel: LHStatusViewModel? {
        didSet {
            statusOriginalView.statusViewModel = statusViewModel
            
            toolBarTop?.uninstall()
            if statusViewModel?.status?.retweeted_status?.text != nil {
                statusRetweetView.statusViewModel = statusViewModel
                statusRetweetView.hidden = false
                
                //更新约束
                statusToolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    self.toolBarTop = make.top.equalTo(statusRetweetView.snp_bottom).constraint
                })
            }else{
                statusRetweetView.hidden = true
                
                //更新约束
                statusToolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    self.toolBarTop = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })
            }
            
            statusToolBarView.statusViewModel = statusViewModel
        }
    }
    
    private lazy var statusOriginalView: LHStatusOriginalView = LHStatusOriginalView()
    private lazy var statusToolBarView: LHStatusToolBar = LHStatusToolBar()
    private lazy var statusRetweetView: LHStatusRetweetView = LHStatusRetweetView()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
        
    }
    
    private func setupUI() {
    
        contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
        contentView.addSubview(statusOriginalView)
        contentView.addSubview(statusRetweetView)
        contentView.addSubview(statusToolBarView)
        
        
        statusOriginalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(8)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
        statusRetweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(statusOriginalView.snp_bottom)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
        statusToolBarView.snp_makeConstraints { (make) -> Void in
            self.toolBarTop = make.top.equalTo(statusRetweetView.snp_bottom).constraint
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            make.height.equalTo(40)
        }
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.bottom.equalTo(statusToolBarView)
        }
    
    }
    
    

    


}
